import { BasicColumn } from '/@/components/Table';
import { h } from 'vue';
import { Tag } from 'ant-design-vue';
//列表数据
export const columns: BasicColumn[] = [
  // {
  //   title: '客户id',
  //   align: "center",
  //   dataIndex: 'customerId'
  // },
  {
    title: '客户名称',
    align: "center",
    dataIndex: 'customerName'
  },
  // {
  //   title: '跟进id',
  //   align: "center",
  //   dataIndex: 'followUpId'
  // },
  {
    title: '产品类别',
    align: "center",
    dataIndex: 'productType'
  },
  {
    title: '产品名称',
    align: "center",
    dataIndex: 'productName',
    width: 150,
    ellipsis: true,
    customRender: ({ text }) => {
      if (!text) return '-';
      // 如果是字符串，尝试解析为数组
      let names = text;
      if (typeof text === 'string') {
        try {
          names = JSON.parse(text);
        } catch (e) {
          // 如果解析失败，按逗号分割
          names = text.split(',').map(item => item.trim()).filter(item => item);
        }
      }
      // 如果是数组，显示为逗号分隔的字符串
      if (Array.isArray(names)) {
        return names.join(', ');
      }
      return text || '-';
    },
  },
  {
    title: '最低价格(元)',
    align: "center",
    dataIndex: 'orderBottom',
    customRender: ({ text }) => (text !== undefined && text !== null && text !== '' ? `${text} 元` : ''),
  },
  {
    title: '最高价格(元)',
    align: "center",
    dataIndex: 'orderPeak',
    customRender: ({ text }) => (text !== undefined && text !== null && text !== '' ? `${text} 元` : ''),
  },
  {
    title: '最终价格(元)',
    align: "center",
    dataIndex: 'finalAmount',
    customRender: ({ text }) => (text !== undefined && text !== null && text !== '' ? `${text} 元` : ''),
  },
  {
    title: '订单状态',
    align: "center",
    dataIndex: 'confirmation_dictText',
    customRender: ({ text }) => {
      if (!text) return '-';
      const colorMap: Record<string, string> = {
        '已确认': 'green',
        '未确认': 'orange',
        '待确认': 'gold',
        '已签订': 'blue',
        '已取消': 'red',
        '草稿': 'default',
      };
      const color = colorMap[text] || 'processing';
      return h(Tag, { color }, () => text);
    }
  },
];

// 高级查询数据
export const superQuerySchema = {
  // customerId: {title: '客户id',order: 0,view: 'text', type: 'string',},
  customerName: {title: '客户名称',order: 1,view: 'text', type: 'string',},
  // followUpId: {title: '跟进id',order: 2,view: 'text', type: 'string',},
  productType: {title: '产品类别',order: 3,view: 'text', type: 'string',},
  productName: {title: '产品名称',order: 4,view: 'text', type: 'string',},
  orderBottom: {title: '最低价格',order: 5,view: 'number', type: 'number',},
  orderPeak: {title: '最高价格',order: 6,view: 'number', type: 'number',},
  finalAmount: {title: '最终价格',order: 7,view: 'number', type: 'number',},
  confirmation: {title: '订单状态',order: 8,view: 'list', type: 'string',dictCode: 'confirmation',},
};

